/* This application is developed by Sameera Bandara
 * this class display the current user location, if user clicks the notification
 */





package com.project.visitAll;

import java.util.List;

import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Point;
import android.os.Bundle;
import android.view.MotionEvent;
import android.widget.LinearLayout;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;

public class Map extends MapActivity {

	LinearLayout linearLayout;
	MapView mapView;
    MapController mapController;
	GeoPoint point;
	double lat;
	double lng;


	@Override
	protected boolean isRouteDisplayed() {
		// TODO Auto-generated method stub
		return false;
	}
	
	class MapOverlay extends com.google.android.maps.Overlay {
         @Override
         public boolean draw(Canvas canvas, MapView mapView, 
         boolean shadow, long when) 
         {
             super.draw(canvas, mapView, shadow);                   
             Point screenPts = new Point();		//translate the GeoPoint to screen pixels
             mapView.getProjection().toPixels(point, screenPts);
  
             Bitmap bmp = BitmapFactory.decodeResource(		//add the marker to the map
                 getResources(), R.drawable.ping);            
             canvas.drawBitmap(bmp, screenPts.x, screenPts.y, null);         
             return true;
         }
         
         
         @Override
         public boolean onTouchEvent(MotionEvent event, MapView mapView) {
         if (event.getAction() == 1) {
        	 point = mapView.getProjection().fromPixels((int) event.getX(), (int) event.getY());
        	 mapController.animateTo(point);
        	 return true;
         } else 
        	 return false;
        } 

     } 

	 public void onCreate(Bundle savedInstanceState) {
	        super.onCreate(savedInstanceState);
	        setContentView(R.layout.main1);
	        Intent intent=getIntent();
	        double[] coordinates=intent.getDoubleArrayExtra("co");
	        setCoordinates(coordinates[0],coordinates[1]);
	        
	        mapView = (MapView) findViewById(R.id.mapview);
	        mapView.setBuiltInZoomControls(true);
	        mapController = mapView.getController();
	        point = new GeoPoint(
	            (int) (lat * 1E6), 
	            (int) (lng * 1E6));
	 
	        mapController.animateTo(point);
	        mapController.setZoom(16); 
	        MapOverlay mapOverlay = new MapOverlay();
	        List<Overlay> listOfOverlays = mapView.getOverlays();
	        listOfOverlays.clear();
	        listOfOverlays.add(mapOverlay);  
	        mapView.invalidate();
	        
	 }
	public void setCoordinates(double lat,double lng){
		this.lat=lat;
		this.lng=lng;
		
	}
}

